package com.example.reagent_management.ui.statistics.helper;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.widget.TextView;

import com.example.reagent_management.R;
import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.MPPointF;

import static android.content.ContentValues.TAG;

public class MyMarkerView extends MarkerView {
    private TextView time;
    private TextView count;

    public MyMarkerView(Context context) {
        super(context, R.layout.custom_markview);
        time = findViewById(R.id.time);
        count = findViewById(R.id.count);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void refreshContent(Entry e, Highlight highlight) {
        try {
            StringBuilder builder = new StringBuilder();
            if (e.getX() <= 86400){
                builder.append((int) e.getX() / 3600).append(":");
                builder.append((int) e.getX()%3600/60).append(":");
                builder.append((int) e.getX()%3600%60);
            }else {
                builder.append((int)  e.getX()/86400).append("日 ");
                builder.append((int) e.getX()%86400 / 3600).append(":");
                builder.append((int) e.getX()%86400 %3600/60).append(":");
                builder.append((int) e.getX()%86400 %3600%60);
            }
            time.setText(builder.toString());
            count.setText((int) e.getY()+"");
        }catch (Exception e1){
            e1.printStackTrace();
        }
        super.refreshContent(e, highlight);
    }

    //布局的偏移量。就是布局显示在圆点的那个位置
    // -(width / 2) 布局水平居中
    //-(height) 布局显示在圆点上方
    @Override
    public MPPointF getOffset() {
        return new MPPointF(-(getWidth() / 2), -getHeight());
    }

}
